extends TextureButton
var utils = globalData.infoDs["g_azurlaneUtils"]
var type = 1
var price = 100
var info = null
signal onPressed(btn)

func _ready():
	pass

func init(id, type = 1, price = null, text = ""):
	self.type = type
	if type == 1:
		var ib = preload("res://ui/item/item.tscn").instance()
		add_child(ib)
		ib.margin_left = 50
		ib.margin_top = 50
		var item:Item = sys.newItem(id)
		ib.init(item)
		ib.dianHide()
		ib.isDrag = false
		setPrice(item.price)
		info = item
	elif type == 2:
		var ib = preload("res://ui/itemBt/itemBt.tscn").instance()
		add_child(ib)
		var cha = sys.main.newChara(id)
		cha.isDrag = true
		cha.team = 2
		ib.init(cha)
		if price != null:setPrice(price)
		else :setPrice(100)
		info = cha
	elif type == 3:
		#资源
		setPrice(price)
		var lb = utils.createRichTextLabel(text, self, Vector2(100, 80))
		lb.rect_position = Vector2(40, 40)
		info = id
	else:
		var ib = Label.new()
		ib.text = text
		ib.z_index = 0
		add_child(ib)
		if price != null:setPrice(price)
		else :setPrice(200)

func setPrice(val):
	price = val
	$Label.text = "%dG" % val

func _on_Button_pressed():
	emit_signal("onPressed", self)
